package com.zhang.entity;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * User: 张
 * Date: 2024-11-27
 * Time: 9:06
 * Description:
 */
@Data
public class Node {
    private String id;
    private String method;
    private String direction;
    private String action;
    private Map<String,String> parameter;
    private List<Node> children;
    public Node(String id,String method,String direction,String action, Map<String,String> parameter){
        this.id = id;
        this.method = method;
        this.direction = direction;
        this.action = action;
        this.parameter = parameter;
        this.children = new ArrayList<>();
    }
    public void addChild(Node node){
        children.add(node);
    }
    public void removeChild(String nodeId){
        for (int i = 0; i < children.size(); i++) {
            if (children.get(i).getId().equalsIgnoreCase(nodeId)){
                children.remove(i);
                break;
            }
        }
    }

    @Override
    public String toString() {
        return "Node{" +
                "id='" + id + '\'' +
                ", method='" + method + '\'' +
                ", action='" + action + '\'' +
                ", parameter=" + parameter.toString() +
                ", children=" + children.toString() +
                '}';
    }
}
